package com.itheima.controller;

import com.itheima.entity.Clazz;
import com.itheima.entity.PageBean;
import com.itheima.entity.Result;
import com.itheima.service.ClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClassController {
@Autowired
    ClassService classService;

    /*
     *  分页查询班级列表
     *
     * */
    @GetMapping
    public Result page( Integer page , Integer PageSize){
        PageBean pageBean =  classService.pageQuery(page,PageSize);
        //3.封装并返回查询结果
        return Result.success(pageBean);
    }
    /*
    * 添加班级
    * */
    @PostMapping()
    public Result save(@RequestBody Clazz clazz){
        classService.saveClass(clazz);

        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result deleteBatch(@PathVariable List<Integer> id) {
        //1. 接受请求参数：请求路径中的参数path，@PathVariable
        log.info("批量删除，ids={}", id);
        //2. 调用业务层，实现批量删除员工
        classService.delete(id);
        //3.封装并返回处理结果
        return Result.success();
    }

}
